#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main()
{
    /*打开文件*/
    const char * filename = "./record.txt";
    int fd = open(filename,O_RDWR | O_CREAT,0644);
    if(fd == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd = %d\n",fd);

    /*将文件的内容读出来*/
    char buffer[128] = {0};

    int requestBytes = sizeof(buffer) - 1;
    while(1)
    {
        int readBytes = read(fd,buffer,requestBytes);
        if((readBytes < requestBytes) || readBytes == 0)
        {
            printf("buffer = %s\n",buffer);
            break;
        }
        printf("buffer = %s\n",buffer);

        memset(buffer,0,sizeof(buffer));
    }
    close(fd);
    
    return 0;
}